package com.workpaper.app.workpaper.daily.providers;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

import com.workpaper.app.consts.format.CommonFormat;
import com.workpaper.app.workpaper.daily.entity.DailyWorkpaper;

public class DailyWorkpaperTableLabelProvider implements ITableLabelProvider{
	/**
	 * 序号
	 */
	private int orderNum = 1;
	
	@Override
	public void addListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
	}

	@Override
	public boolean isLabelProperty(Object element, String property) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void removeListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		return null;
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		if(element == null) {
			return null;
		}
		if(!(element instanceof DailyWorkpaper)) {
			return null;
		}
		DailyWorkpaper wd = (DailyWorkpaper) element;
		switch (columnIndex) {
		case 0:
			return "" + (orderNum++);
		case 1:
			return DateFormatUtils.format(wd.getWorkDate(), CommonFormat.DATE_FORMAT);
		case 2:
			return wd.getContent();
		case 3:
			return wd.getMaster();
		case 4:
			return wd.getRemark();
		case 5:
			return wd.getId();
		default:
			return null;
		}
	}

	public void reset() {
		orderNum = 1;
	}
}
